local xingzu = fk.CreateSkill{
  name = "xiaobai__xingzu",
  tags = {Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["xiaobai__xingzu"] = "兴族",
  [":xiaobai__xingzu"] = "锁定技，游戏开始时，你选择一名其他角色：其摸牌阶段多摸一张牌且手牌上限+1；其因弃置或打出而失去牌后，你摸一张牌"..
  "（每回合至多摸5张）；其死亡后，你直接死亡。",
  ["#xiaobai__xingzu-choose"] = "兴族：选择一名“兴族”目标角色",
  ["@xiaobai__xingzu"] = "兴族",

  ["$xiaobai__xingzu1"] = "父为国朝股肱，兄怀兴族大才，且乐其融融。",
  ["$xiaobai__xingzu2"] = "吾家通天之贵，奉我一身！",
}

xingzu:addEffect(fk.GameStart, {
  anim_type = "special",
  audio_index = 1,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and #player.room:getOtherPlayers(player) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = room:getOtherPlayers(player)
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1, 
      prompt = "#xiaobai__xingzu-choose", 
      skill_name = xingzu.name,
      cancelable = false, 
      no_indicate = false})
    to = to[1]
    room:setPlayerMark(player, "@xiaobai__xingzu", to.general)
    room:setPlayerMark(player, xingzu.name, to.id)
  end,
})

xingzu:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  audio_index = 2,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and player:getMark("xiaobai__xingzu-turn") < 5 then
      for _, move in ipairs(data) do
        if move.from and move.from.id == player:getMark(xingzu.name) and (move.moveReason == fk.ReasonResponse or move.moveReason == fk.ReasonDiscard) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "xiaobai__xingzu-turn", 1)
    player:drawCards(1, xingzu.name)
  end
})

xingzu:addEffect(fk.Deathed,{
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:getMark(xingzu.name) == target.id
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, xingzu.name, "negative")
    room:killPlayer{
      who = player
    }
  end
})

xingzu:addEffect(fk.DrawNCards, {
  can_refresh = function (self, event, target, player, data)
    return target == player and
      table.find(player.room.alive_players, function (p)
        return p:getMark(xingzu.name) == player.id
      end)
  end,
  on_refresh = function (self, event, target, player, data)
    data.n = data.n + #table.filter(player.room.alive_players, function (p)
      return p:getMark(xingzu.name) == player.id
    end)
  end,
})

xingzu:addEffect("maxcards", {
  correct_func = function(self, player)
    return #table.filter(Fk:currentRoom().alive_players, function (p)
      return p:getMark("xiaobai__xingzu") == player.id
    end)
  end,
})

return xingzu